package com.dhcc.sds.standard.entity;

import com.baomidou.mybatisplus.annotations.TableName;
import com.dhcc.core.framework.base.entity.TreeEntity;
import com.dhcc.core.framework.constant.Const;
import com.dhcc.core.framework.util.CommonUtil;



/**
 /**
 * 新数据源定义
 *
 * @author lyh
 * @ClassName: SdsStandDataSourceEntity
 * @Description:
 */

@TableName("t_sds_std_datasource")
public class SdsStandSourceEntity extends TreeEntity<SdsStandSourceEntity> {

	private static final long serialVersionUID = 1L;
	// 数据源编码
	private String sourceCode;
	// 数据源名称
	private String sourceDesc;
	// 数据源是否有效
	private Integer isActive;
	// 备注
	private String resume;
	// 层级
	private Integer levels;
//	// 父级ID
//	private Long parentId;

	public String getSourceCode() {
		return sourceCode;
	}

	public void setSourceCode(String sourceCode) {
		this.sourceCode = sourceCode;
	}

	public String getSourceDesc() {
		return sourceDesc;
	}

	public void setSourceDesc(String sourceDesc) {
		this.sourceDesc = sourceDesc;
	}

	public Integer getIsActive() {
		return isActive;
	}

	public void setIsActive(Integer isActive) {
		this.isActive = isActive;
	}

	public String getResume() {
		return resume;
	}

	public void setResume(String resume) {
		this.resume = resume;
	}

	public Integer getLevels() {
		return levels;
	}

	public void setLevels(Integer levels) {
		this.levels = levels;
	}



	/**
	 * 根据请求的父级编号设置和层级
	 */
	public void init() {
		if (CommonUtil.isEmpty(this.getParentId()) || this.getParentId() == 0) {
			this.setParentId(Const.TREE_ROOT_ID);
			this.setPath("[" + Const.TREE_ROOT_ID + "]");
			this.setLevels(1);
		} else {
			TreeEntity<?> parent = (TreeEntity<?>) this.selectById(this.getParentId());
			this.setParentId(parent.getId());
			this.setPath(parent.getPath() + ",[" + parent.getId() + "]");
			this.setLevels(parent.getLevels()+1);
		}
	}
}
